<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="js/vue.js"></script>
    <style>
        
    </style>
</head>
<body>
    <div id="box">
        <button @click="isShow=!isShow">显示|隐藏</button>
        <tab-bar v-if="isShow"></tab-bar>
    </div>
    <script>
        Vue.component("tabBar",{
            template:`<div>
                子组件
            </div>`,
            data(){
                return {
                    num:0,
                    timer:null
                }
            },
            mounted(){
                this.timer = setInterval(() => {
                    console.log(++this.num);
                },500)
            },
            beforeDestroy(){
                console.log("beforeDestroy");
            },
            destroyed(){
                console.log("destroyed");
                clearInterval(this.timer)
            }
        })
        // 生命周期函数
        const vm = new Vue({
            el:"#box",
            data:{
                msg:"生命周期",
                isShow:true
            },
            beforeCreate(){
                console.log("beforeCreate",this.msg);
            },
            created(){
                console.log("created",this.msg);
                // ajax请求
            },
            beforeMount(){
                console.log("beforeMount",this.msg); 

            },
            mounted(){
                console.log("mounted",this.msg); 
                // ajax请求
                this.$nextTick(() => {
                    // 这里执行的代码包含所有子组件都挂载完毕
                    console.log("nextTick");
                    
                })
            },
            beforeUpdate(){
                console.log("beforUpdate");
            },
            updated(){
                console.log("updated");
            }

        })
    </script>
</body>
</html>